package dbOperator;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.ResultSetMetaData;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class AdvancedOperation {
	/**
	 * 这个函数的作用是根据用户的ID号确定其身份为 读者、图书管理员还是超级管理员，其中 1是超级管理员，2是图书管理员，3是读者，返回值为0表示当前用户不存在
	 * @author Admin
	 * @param uid 用户的ID号
	 * @return identity 用户的身份代号
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static int getIdentity(int uid) throws SQLException {
		Connection con = BasicOperation.getConnection();
		ResultSet rs = BasicOperation.getQueryResult(con, "select identity from User where uid = " + uid);
		if (rs.next()) {
			int identity = rs.getInt(1);
			con.close();
			return identity;
		}
		return 0;
	}

	/**
	 * 这个函数的作用是根据用户的ID号确定其身份为 读者、图书管理员还是超级管理员，其中 1是超级管理员，2是图书管理员，3是读者，返回值为0表示当前用户不存在
	 * @author Admin
	 * @param con 建立的数据库连接
	 * @param uid 用户的ID号
	 * @return identity 用户的身份代号
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static int getIdentity(Connection con, int uid) throws SQLException {
		ResultSet rs = BasicOperation.getQueryResult(con, "select identity from User where uid = " + uid);
		if (rs.next()) {
			int identity = rs.getInt(1);
			return identity;
		}
		return 0;
	}

	/**
	 * 这个函数的作用是根据用户的信息获取其uid，信息可以是邮箱号或手机号，函数可以自动做出判断
	 * @author Admin
	 * @param information 基本信息，可以是手机号或邮箱
	 * @return 用户的ID
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static int getUid(String information) throws SQLException {
		int isEmail = information.indexOf("@");
		Connection con = BasicOperation.getConnection();
		information = "'" + information + "'";
		String queryScript = "";
		if (isEmail != -1) {
			queryScript = "select uid from User where Email = " + information;
		} else
			queryScript = "select uid from User where phoneNumber = " + information;
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		int uid = -1;
		if (res.next())
			uid = res.getInt(1);
		return uid;
	}

	/**
	 * 这个函数的作用是根据用户的信息获取其uid，信息可以是邮箱号或手机号，函数可以自动做出判断
	 * @author Admin
	 * @param con         建立的数据库连接
	 * @param information 基本信息，可以是手机号或邮箱
	 * @return 用户的ID
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static int getUid(Connection con, String information) throws SQLException {
		int isEmail = information.indexOf("@");
		information = "'" + information + "'";
		String queryScript = "";
		if (isEmail != -1) {
			queryScript = "select uid from User where Email = " + information;
		} else
			queryScript = "select uid from User where phoneNumber = " + information;
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		int uid = -1;
		if (res.next())
			uid = res.getInt(1);
		return uid;
	}

	/**
	 * 这个函数能根据cookie中的信息取得用户的id，如果当前用户的登录信息依然有效的话
	 * @author Admin
	 * @param cookie 用户的关键登录信息
	 * @return 用户的id
	 * @throws SQLException 查询语句执行错误时抛出此异常
	 */
	public static int getUidbyCookie(String cookie) throws SQLException {
		Connection con = BasicOperation.getConnection();
		cookie = "'" + cookie + "'";
		String queryScript = "";
		queryScript = "select uid from User where recentCookie = " + cookie;
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		int uid = -1;
		if (res.next())
			uid = res.getInt(1);
		con.close();
		return uid;
	}

	/**
	 * 这个函数能根据cookie中的信息取得用户的id，如果当前用户的登录信息依然有效的话
	 * @author Admin
	 * @param con    数据库连接
	 * @param cookie 用户的关键登录信息
	 * @return 用户的id
	 * @throws SQLException 查询语句执行错误时抛出此异常
	 */
	public static int getUidbyCookie(Connection con, String cookie) throws SQLException {
		cookie = "'" + cookie + "'";
		String queryScript = "";
		queryScript = "select uid from User where recentCookie = " + cookie;
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		int uid = -1;
		if (res.next())
			uid = res.getInt(1);
		return uid;
	}

	/**
	 * 这个函数的作用是根据用户的信息获取在数据库中记录的最近一条Cookie，信息可以是邮箱号或手机号，函数可以自动做出判断
	 * @author Admin
	 * @param information 基本信息，可以是手机号或邮箱
	 * @return 用户的最近一条(recent)Cookie
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static String getUserCookie(String information) throws SQLException {
		int isEmail = information.indexOf("@");
		information = "'" + information + "'";
		String queryScript = "";
		if (isEmail != -1) {
			queryScript = "select recentCookie from User where Email = " + information;
		} else
			queryScript = "select recentCookie from User where phoneNumber = " + information;
		//System.out.println(queryScript);
		Connection con = BasicOperation.getConnection();
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		String recentCookie = null;
		if (res.next())
			recentCookie = res.getString(1);
		con.close();
		return recentCookie;
	}

	/**
	 * 这个函数的作用是根据用户的信息获取在数据库中记录的最近一条Cookie，信息可以是邮箱号或手机号，函数可以自动做出判断
	 * @author Admin
	 * @param con         数据库连接
	 * @param information 基本信息，可以是手机号或邮箱
	 * @return 用户的最近一条(recent)Cookie
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static String getUserCookie(Connection con, String information) throws SQLException {
		int isEmail = information.indexOf("@");
		information = "'" + information + "'";
		String queryScript = "";
		if (isEmail != -1) {
			queryScript = "select recentCookie from User where Email = " + information;
		} else
			queryScript = "select recentCookie from User where phoneNumber = " + information;
		System.out.println(queryScript);
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		String recentCookie = null;
		if (res.next())
			recentCookie = res.getString(1);
		return recentCookie;
	}

	/**
	 * 这个函数的作用是根据用户的ID在数据库中记录的最近一条Cookie
	 * @author Admin
	 * @param uid 用户的ID
	 * @return 用户的最近一条(recent)Cookie
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static String getUserCookie(int uid) throws SQLException {
		String queryScript = "select recentCookie from User where uid = " + uid;
		Connection con = BasicOperation.getConnection();
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		String recentCookie = null;
		if (res.next())
			recentCookie = res.getString(1);
		con.close();
		return recentCookie;
	}

	/**
	 * 这个函数的作用是根据用户的ID在数据库中记录的最近一条Cookie
	 * @author Admin
	 * @param con 数据库连接
	 * @param uid 用户的ID
	 * @return 用户的最近一条(recent)Cookie
	 * @throws SQLException 数据库查询语句执行错误时会抛出此异常
	 */
	public static String getUserCookie(Connection con, int uid) throws SQLException {
		String queryScript = "select recentCookie from User where uid = " + uid;
		ResultSet res = BasicOperation.getQueryResult(con, queryScript);
		String recentCookie = null;
		if (res.next())
			recentCookie = res.getString(1);
		return recentCookie;
	}

	/**
	 * 这个函数的作用是为系统注册新用户
	 * @author Admin
	 * @param Email              用户的电子邮箱
	 * @param phoneNumber        用户的手机号
	 * @param registrantIdentity 注册者的身份，实际使用时请通过其他函数提供，不要填为定值
	 * @param registeredIdentity 被注册者的身份，实际使用时可以填为定值 说明：当被注册者的身份-注册者身份 = 1
	 *                           的时候注册行为被认为是合法的
	 * @return update语句自带的的返回值
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static int registerNewUser(String Email, String phoneNumber, int registrantIdentity, int registeredIdentity)
			throws SQLException {
		if (phoneNumber == null || Email == null)
			return -1;
		if (registeredIdentity - registrantIdentity == 1) {
			Email = "'" + Email + "'";
			phoneNumber = "'" + phoneNumber + "'";
			String defaultPassword = "";
			if (registeredIdentity == 3)
				defaultPassword = "MD5('12345678')";
			else if (registeredIdentity == 2)
				defaultPassword = "MD5('00010001')";
			else
				return -1;
			String updateScript = "insert into User values(NULL," + Email + "," + phoneNumber + ",NULL,"
					+ registeredIdentity + "," + defaultPassword + ")";
			return BasicOperation.executeUpdateScript(updateScript);
		}
		return -1;
	}

	/**
	 * 这个函数的作用是为系统注册新用户
	 * @author Admin
	 * @param con                数据库连接
	 * @param Email              用户的电子邮箱
	 * @param phoneNumber        用户的手机号
	 * @param registrantIdentity 注册者的身份，实际使用时请通过其他函数提供，不要填为定值
	 * @param registeredIdentity 被注册者的身份，实际使用时可以填为定值 说明：当被注册者的身份-注册者身份 = 1
	 *                           的时候注册行为被认为是合法的
	 * @return update语句自带的的返回值
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static int registerNewUser(Connection con, String Email, String phoneNumber, int registrantIdentity,
			int registeredIdentity) throws SQLException {
		if (registeredIdentity - registrantIdentity == 1) {
			Email = "'" + Email + "'";
			phoneNumber = "'" + phoneNumber + "'";
			String defaultPassword = "";
			if (registeredIdentity == 3)
				defaultPassword = "MD5('12345678')";
			else if (registeredIdentity == 2)
				defaultPassword = "MD5('00010001')";
			else
				return -1;
			String updateScript = "insert into User values(NULL," + Email + "," + phoneNumber + ",NULL,"
					+ registeredIdentity + "," + defaultPassword + ")";
			return BasicOperation.executeUpdateScript(con, updateScript);
		}
		return -1;
	}

	/**
	*这个函数的作用是添加读者时存入保证金
	*@param con 数据库连接
	*@param uid 用户Uid
	* @throws SQLException 
	*
	**/
	public static void addDeposit(Connection con, String email) throws SQLException {
		int uid = getUid(con, email);
		double deposit = getSecurityDeposit(con);
		String sql = "insert into FineList values(" + uid + ", 'null', '" + dataOperator.BasicOperation.getDateWithTimeInString() + "', " + deposit +", 'Deposit')";
		BasicOperation.executeUpdateScript(con, sql);
	}

	/**
	 * 这个函数用来校验用户的信息(邮箱或手机号)和密码是否正确输入，如果输入正确，函数会更新并返回用户的登录信息(cookie)，否则返回空字符串
	 * @author Admin
	 * @param information 用户的信息
	 * @param password    用户的密码
	 * @throws SQLException 查询语句或更新语句执行异常时会抛出此异常
	 */
	public static String getLoginInfo(String information, String password) throws SQLException {
		String type = "phoneNumber";
		if (information.indexOf('@') != -1)
			type = "Email";
		password = "'" + password + "'";
		String queryScript = "select * from User where " + type + " = '" + information + "' and password = " + password
				+ "";
		Connection con = BasicOperation.getConnection();
		ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			String updateScript = "update User set recentCookie = MD5('" + information + System.currentTimeMillis()
					+ "') where " + type + " = '" + information + "' and password = " + password + "";
			BasicOperation.executeUpdateScript(con, updateScript);
			con.close();
			return getUserCookie(information);
		}
		con.close();
		return null;
	}

	/**
	 * 这个函数用来校验用户的信息(邮箱或手机号)和密码是否正确输入，如果输入正确，函数会更新并返回用户的登录信息(cookie)，否则返回空字符串
	 * @author Admin
	 * @param con         数据库连接
	 * @param information 用户的信息
	 * @param password    用户的密码
	 * @throws SQLException 查询语句或更新语句执行异常时会抛出此异常
	 */
	public static String getLoginInfo(Connection con, String information, String password) throws SQLException {
		String type = "phoneNumber";
		if (information.indexOf('@') != -1)
			type = "Email";
		password = "'" + password + "'";
		String queryScript = "select * from User where " + type + " = '" + information + "' and password = " + password
				+ "";
		ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			String updateScript = "update User set recentCookie = MD5('" + information + System.currentTimeMillis()
					+ "') where " + type + " = '" + information + "' and password = " + password + "";
			BasicOperation.executeUpdateScript(con, updateScript);
			return getUserCookie(con, information);
		}
		return null;
	}

// 以下函数的作者是谢逸	
/**
	 * 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * 
	 * @author xy
	 * @param con        数据库链接
	 * @param inputValue 搜索框输入内容
	 * @param condition  查找方式
	 * @return Book结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet getBorrowList(Connection con, String inputValue, String condition) throws SQLException {
		if (condition.equals("bid")) { 
			ResultSet rs = BasicOperation.getQueryResult(con, "select * from BorrowList where bid like '%"+inputValue+"%' order by uid asc");
			return rs;
		} else { 
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from BorrowList where " + condition + " = '" + inputValue + "' order by uid asc");
			return rs;
		}
	}
	/**
	 * 这个函数的作用是根据输入内容获取书籍的信息，输入内容可以是书名、ISBN、bookID，用户在输入时需要用下拉框选择按哪一种方式查找（默认为书名），输入书名时若有多个关键词需以空格分割
	 * 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con        数据库链接
	 * @param inputValue 搜索框输入内容
	 * @param condition  查找方式
	 * @return Book结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet getBookInfo(Connection con, String inputValue, String condition) throws SQLException {
		if (condition.equals("bid")) { // 根据书本ID进行查询
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from Book where bid ='" + inputValue
							+ "' order by bid asc");
			return rs;
		} else { // 根据书本ISBN、书名进行查询，可实现书名的模糊化查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from Book where " + condition + " like " + "'%" + inputValue + "%' order by bid asc");
			return rs;
		}
	}
	
	/**
	 * 这个函数的作用是根据输入内容获取一本书的信息，输入内容可以是bid,bookID,status用户在输入时需要用下拉框选择按哪一种方式查找（默认为书名），输入书名时若有多个关键词需以空格分割
	 * 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con        数据库链接
	 * @param inputValue 搜索框输入内容
	 * @param condition  查找方式
	 * @return 结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet getSpecificBookInfo(Connection con, String inputValue, String condition) throws SQLException {
		if (condition.equals("bookID")) { // 根据书本ID进行查询
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from SpecificBook where bookID = '" + inputValue
							+ "' order by bid asc");
			return rs;
		}
		if (condition.equals("bid")) { // 根据书类进行查询
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from SpecificBook where bid = '" + inputValue
							+ "' order by bid asc");
			return rs;
		}
		else{ //可实现副本状态模糊化查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from SpecificBook where " + condition + " like '%" + inputValue + "%' order by bid asc");
			return rs;
		}
	}
	/**
	 * 这个函数的作用是根据输入内容获取一本书的信息，输入内容可以是bid,bookID,status用户在输入时需要用下拉框选择按哪一种方式查找（默认为书名），输入书名时若有多个关键词需以空格分割
	 * 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con        数据库链接
	 * @param inputValue 搜索框输入内容
	 * @param condition  查找方式
	 * @return 结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet getReaderInfo(Connection con, String inputValue, String condition) throws SQLException {
		if (condition.equals("uid")) { // 根据读者ID进行查询
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where uid = '" + inputValue
							+ "' and identity = 3 order by uid asc");
			return rs;
		}
		if (condition.equals("Email")) { // 根据Email进行查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where Email like '%" + inputValue + "%' and identity = 3 order by uid asc");
			return rs;
		}
		else{ //根据phoneNumber进行查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where phoneNumber like '%" + inputValue + "%' and identity = 3 order by uid asc");
			return rs;
		}
	}

	/**
	 * 这个函数的作用是Reader/Librarian查询借阅/归还记录 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con       数据库链接
	 * @param userID    查询者的uid condition判断借阅/归还
	 * @param condition 设定查询借阅/归还
	 * @return BorrowList 结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet viewBorrowReturnHistory(Connection con, int userID, String condition) throws SQLException {
		int userIdentity = getIdentity(con, userID);
		if (userIdentity == 2) { // identity=2，Librarian可执行操作，查询所有Reader的借阅/归还，condition判断借阅/归还
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from BorrowList where status like '%" + condition + "%'");
			if (rs.next()) {
				return rs;
			}
		}
		if (userIdentity == 3) { // identity=3，Reader可执行操作，查询自己的借阅/归还，condition判断查找借阅/归还
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from BorrowList where uid = " + userID + "and status like '%" + condition + "%'");
			if (rs.next()) {
				return rs;
			}
		}
		return null;
	}

	/**
	 * 函数重载，用于Librarian查询指定readerID的借阅/归还的情况 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con       数据库链接
	 * @param userID    查询者的uid
	 * @param condition 设定查询借阅/归还
	 * @param readerID  Librarian指定的查询对象
	 * @return BorrowList 结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet viewBorrowReturnHistory(Connection con, int userID, String condition, int readerID)
			throws SQLException {
		if (getIdentity(con, userID) == 2) { // identity=2，Librarian可执行操作，查询指定Reader的借阅/归还
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from BorrowList where uid = " + readerID + "and status like '%" + condition + "%'");
			if (rs.next()) {
				return rs;
			}
		}
		return null;
	}

	/**
	 * 此函数用于Librarian/Reader查询罚金记录 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con    数据库链接
	 * @param userID 判断用户身份
	 * @return FineList结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet viewFineHistory(Connection con, int userID) throws SQLException {
		int userIdentity = getIdentity(con, userID);
		if (userIdentity == 2) { // identity=2,Librarian可执行操作,查询所有Reader的FineHistory
			ResultSet rs = BasicOperation.getQueryResult(con, "select * from FineList");
			if (rs.next()) {
				return rs;
			}
		}
		if (userIdentity == 3) { // identity=3,Reader可执行操作,查询自己的FineHistory
			ResultSet rs = BasicOperation.getQueryResult(con, "select * from FineList where uid = " + userID);
			if (rs.next()) {
				return rs;
			}
		}
		return null;
	}

	/**
	 * 函数重载，用于Librarian查询指定Reader的罚金记录 注：此函数返回结果为结果集，需要调用者提供连接数据库的链接
	 * @author xy
	 * @param con    数据库链接
	 * @param userID readerID是Librarian指定的查询对象
	 * @return FineList结果集
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static ResultSet viewFineHistory(Connection con, int userID, int readerID) throws SQLException {
		if (getIdentity(con, userID) == 2) { // identity=2,Librarian可执行操作,查询指定Reader的FineHistory
			ResultSet rs = BasicOperation.getQueryResult(con, "select * from FineList where uid =" + readerID);
			if (rs.next()) {
				return rs;
			}
		}
		return null;
	}

// 以下函数的作者是胡兰氪
	/**
	 * 这个函数的作用是根据bid为系统添加新书
	 * @author hlk
	 * @param con 数据库连接
	 * @param uid 被注册者的身份，实际使用时可以填为定值 说明：当被注册者的身份!= 2 的时候增书行为被认为是非法的
	 * @param bid 书的id
	 * @param num 增书数量
	 * @return void
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static void addBooksbybid(Connection con, int uid, int bid, int num) throws SQLException {
		int identity = getIdentity(con, uid);
		String bookid = null;
		if (identity != 2)
			return;
		while (num-- > 0) {
			bookid = bid + System.currentTimeMillis() + Integer.toString(num);
			bookid = "MD5('" + bookid + "')";
			String sql = "insert into SpecificBook(bookID,position,status,bid) values(" + bookid + ",NULL,'available'," + bid
					+ ")";
			BasicOperation.executeUpdateScript(con, sql);
		}
		con.close();
		return;
	}

	/**
	 * 这个函数的作用是根据bid为系统添加新书
	 * @author hlk
	 * @param uid 被注册者的身份，实际使用时可以填为定值 说明：当被注册者的身份!= 2 的时候增书行为被认为是非法的
	 * @param bid 书的id
	 * @param num 增书数量
	 * @return void
	 * @throws SQLException 插入语句执行错误时会抛出此异常
	 */
	public static void addBooksbybid(int uid, int bid, int num) throws SQLException {
		int identity = getIdentity(uid);
		String bookid = null;
		if (identity != 2)
			return;
		Connection con = BasicOperation.getConnection();
		while (num-- > 0) {
			bookid = bid + System.currentTimeMillis() + Integer.toString(num);
			bookid = "MD5('" + bookid + "')";
			String sql = "insert into SpecificBook(bookID,position,status,bid) values(" + bookid + ",NULL,'available'," + bid
					+ ")";
			BasicOperation.executeUpdateScript(con, sql);
		}
		con.close();
		return;
	}


//以下函数的作者是贾泽坤
	/**
	 * 这个函数的作用是用户修改个人信息
	 * @author jzk
	 * @param newEmail       被修改读者的电子邮箱
	 * @param newPhoneNumber 被修改读者的手机号
	 * @param updaterUid     修改者的UID，实际使用时请通过其他函数提供，不要填为定值
	 * @param updatedUid     被修改用户的UID，实际使用时请通过修改者选择的读者UID提供，不要填为定值
	 * @return update语句自带的的返回值
	 * @throws SQLException SQL语句执行错误时会抛出此异常
	 */
	public static int updateUserInfo(String newEmail, String newPhoneNumber, int updaterUid, int updatedUid)
			throws SQLException {
		Connection con = BasicOperation.getConnection();
		int updaterIdentity = getIdentity(con, updaterUid);
		ResultSet rs1 = BasicOperation.getQueryResult(con,
				"select Email,phoneNumber from User where uid=" + updatedUid);
		String originalEmail = null;
		String originalPhoneNumber = null;
		if (rs1.next()) {
			originalEmail = rs1.getString(1);
			originalPhoneNumber = rs1.getString(2);
		}
		if (newEmail == null||newEmail.indexOf('@')==-1) {
			newEmail = originalEmail;
		}
		if (newPhoneNumber == null||newPhoneNumber.equals("")) {
			newPhoneNumber = originalPhoneNumber;
		}
		if (updaterIdentity == 3 || updaterIdentity == 2) {
			if (updaterIdentity == 3)
				updatedUid = updaterUid;
			newEmail = "'" + newEmail + "'";
			newPhoneNumber = "'" + newPhoneNumber + "'";
			String updateScript = "update User Set Email = " + newEmail + ", phoneNumber = " + newPhoneNumber
					+ " where uid = " + updatedUid;
			int i = BasicOperation.executeUpdateScript(con,updateScript);
			con.close();
			return i;
		} else if (updaterIdentity == 1) {
			int updatedIdentity = getIdentity(con, updatedUid);
			if(updatedIdentity == 2) {
				newEmail = "'" + newEmail + "'";
				newPhoneNumber = "'" + newPhoneNumber + "'";
				String updateScript = "update User Set Email = " + newEmail + ", phoneNumber = " + newPhoneNumber
						+ " where uid = " + updatedUid;
				int i = BasicOperation.executeUpdateScript(con,updateScript);
				con.close();
				return i;
			}
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是用户修改个人信息
	 * @author jzk
	 * @param con            数据库连接
	 * @param newEmail       被修改读者的电子邮箱
	 * @param newPhoneNumber 被修改读者的手机号
	 * @param updaterUid     修改者的UID，实际使用时请通过其他函数提供，不要填为定值
	 * @param updatedUid     被修改用户的UID，实际使用时请通过修改者选择的读者UID提供，不要填为定值
	 * @return update语句自带的的返回值
	 * @throws SQLException SQL语句执行错误时会抛出此异常
	 */
	public static int updateUserInfo(Connection con, String newEmail, String newPhoneNumber, int updaterUid,
			int updatedUid) throws SQLException {
		int updaterIdentity = getIdentity(con, updaterUid);
		ResultSet rs1 = BasicOperation.getQueryResult(con,
				"select Email,phoneNumber from User where uid=" + updatedUid);
		String originalEmail = null;
		String originalPhoneNumber = null;
		if (rs1.next()) {
			originalEmail = rs1.getString(1);
			originalPhoneNumber = rs1.getString(2);
		}
		if (newEmail == null||newEmail.indexOf('@')==-1) {
			newEmail = originalEmail;
		}
		if (newPhoneNumber == null||newPhoneNumber.equals("")) {
			newPhoneNumber = originalPhoneNumber;
		}
		if (updaterIdentity == 3 || updaterIdentity == 2) {
			if (updaterIdentity == 3)
				updatedUid = updaterUid;
			newEmail = "'" + newEmail + "'";
			newPhoneNumber = "'" + newPhoneNumber + "'";
			String updateScript = "update User Set Email = " + newEmail + ", phoneNumber = " + newPhoneNumber
					+ " where uid = " + updatedUid;
			int i = BasicOperation.executeUpdateScript(con,updateScript);
			return i;
		} else if (updaterIdentity == 1) {
			int updatedIdentity = getIdentity(con, updatedUid);
			if(updatedIdentity == 2) {
				newEmail = "'" + newEmail + "'";
				newPhoneNumber = "'" + newPhoneNumber + "'";
				String updateScript = "update User Set Email = " + newEmail + ", phoneNumber = " + newPhoneNumber
						+ " where uid = " + updatedUid;
				int i = BasicOperation.executeUpdateScript(con,updateScript);
				return i;
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是修改用户密码
	 * @author jzk
	 * @param changerUid  这是修改者的UID
	 * @param changedUid  这是被修改者的UID
	 * @param confirmPassword 确认密码，当自行修改密码时需要提供旧密码，当修改低一级用户的密码时需要提供自己的密码
	 * @param newPassword 这是修改后的密码
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int changePassword(int changerUid, int changedUid,String confirmPassword, String newPassword) throws SQLException {
		if (newPassword == null) {
			System.out.println("请输入修改后的密码！");
			return -1;
		}
		Connection con = BasicOperation.getConnection();
		int changerIdentity = getIdentity(con,changerUid);
		int changedIdentity = getIdentity(con,changedUid);
		if (changedIdentity - changerIdentity >= 0) {
			if(changerIdentity == changedIdentity) changerUid = changedUid;
			newPassword = "MD5('" + newPassword + "')";
			String queryScript = "select * from User where uid = " + changerUid + " and password = '" + dataOperator.BasicOperation.MD5(confirmPassword) + "'";
			System.out.println(queryScript);
			ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
			if(rs.next()) {
				String updateScript = "update User set password = " + newPassword + ",recentCookie=NULL where uid = " + changedUid;
				System.out.println(updateScript);
				int i = BasicOperation.executeUpdateScript(con, updateScript);
				con.close();
				return i;
			}
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是修改用户密码
	 * @author jzk
	 * @param con         数据库连接
	 * @param changerUid  这是修改者的UID
	 * @param changedUid  这是被修改者的UID
	 * @param confirmPassword 确认密码，当自行修改密码时需要提供旧密码，当修改低一级用户的密码时需要提供自己的密码
	 * @param newPassword 这是修改后的密码
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int changePassword(Connection con, int changerUid, int changedUid,String confirmPassword, String newPassword)
			throws SQLException {
		if (newPassword == null) {
			System.out.println("请输入修改后的密码！");
			return -1;
		}
		int changerIdentity = getIdentity(con, changerUid);
		int changedIdentity = getIdentity(con, changedUid);
		if (changedIdentity - changerIdentity >= 0) {
			if(changerIdentity == changedIdentity) changerUid = changedUid;
			newPassword = "MD5('" + newPassword + "')";
			String queryScript = "select * from User where uid = " + changerUid + " and password = '" + dataOperator.BasicOperation.MD5(confirmPassword) + "'";
			ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
			if(rs.next()) {
				String updateScript = "update User set password = " + newPassword + ",recentCookie=NULL where uid = " + changedUid;
				return BasicOperation.executeUpdateScript(con, updateScript);
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是修改滞纳金（罚金）
	 * @author jzk
	 * @param updaterUid 这是修改者的UID
	 * @param fineValue  这是修改后罚金的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateFineValue(int updaterUid, double fineValue) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		if (identity == 1) {
			if (fineValue < 0) {
				System.out.println("罚金不得为负！");
				con.close();
				return -1;
			} else if (fineValue >= 0) {
				String updateScript = "update SystemAttribute set bookFineValue =" + fineValue;
				int i = BasicOperation.executeUpdateScript(con,updateScript);
				con.close();
				return i;
			}
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是修改滞纳金（罚金）
	 * @author jzk
	 * @param con        数据库连接
	 * @param updaterUid 这是修改者的UID
	 * @param fineValue  这是修改后罚金的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateFineValue(Connection con, int updaterUid, double fineValue) throws SQLException {
		int identity = getIdentity(con, updaterUid);
		if (identity == 1) {
			if (fineValue < 0) {
				System.out.println("罚金不得为负！");
				return -1;
			} else if (fineValue > 0) {
				String updateScript = "update SystemAttribute set bookFineValue =" + fineValue;
				return BasicOperation.executeUpdateScript(con, updateScript);
			} else
				return -1;
		}
		return -1;
	}

	/**
	 * 这个函数的作用是获取当前罚金值
	 * @author jzk
	 * @return fineValue 当前罚金值
	 * @throws SQLException
	 */
	public static double getFineValue() throws SQLException {
		double fineValue = 0;
		Connection con = BasicOperation.getConnection();
		ResultSet rs;
		String queryScript = "select bookFineValue from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			fineValue = rs.getDouble(1);
			rs.close();
			con.close();
			return fineValue;
		}
		return 0.0;
	}

	/**
	 * 这个函数的作用是获取当前罚金值
	 * @author jzk
	 * @param con 数据库连接
	 * @return fineValue 当前罚金值
	 * @throws SQLException
	 */
	public static double getFineValue(Connection con) throws SQLException {
		double fineValue = 0;
		ResultSet rs;
		String queryScript = "select bookFineValue from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			fineValue = rs.getDouble(1);
			rs.close();
			return fineValue;
		}
		return 0.0;
	}

	/**
	 * 这个函数的作用是修改归还期限
	 * @author jzk
	 * @param updaterUid   这是修改者的UID
	 * @param returnPeriod 这是修改后归还期的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateReturnPeriod(int updaterUid, int returnPeriod) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		if (identity == 1) {
			if (returnPeriod <= 0) {
				System.out.println("归还期必须为正（天数）！");
				con.close();
				return -1;
			} else {
				String updateScript = "update SystemAttribute set bookReturnPeriod =" + returnPeriod;
				int i = BasicOperation.executeUpdateScript(con,updateScript);
				con.close();
				return i;
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是修改归还期限
	 * @author jzk
	 * @param con          数据库连接
	 * @param updaterUid   这是修改者的UID
	 * @param returnPeriod 这是修改后归还期的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateReturnPeriod(Connection con, int updaterUid, int returnPeriod) throws SQLException {
		int identity = getIdentity(con, updaterUid);
		if (identity == 1) {
			if (returnPeriod <= 0) {
				System.out.println("归还期必须为正（天数）！");
				return -1;
			} else {
				String updateScript = "update SystemAttribute set bookReturnPeriod =" + returnPeriod;
				return BasicOperation.executeUpdateScript(con, updateScript);
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是获取当前归还期
	 * @author jzk
	 * @return returnPeriod 当前归还期
	 * @throws SQLException
	 */
	public static int getReturnPeriod() throws SQLException {
		int returnPeriod = 0;
		Connection con = BasicOperation.getConnection();
		ResultSet rs;
		String queryScript = "select bookReturnPeriod from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			returnPeriod = rs.getInt(1);
		}
		rs.close();
		con.close();
		return returnPeriod;
	}

	/**
	 * 这个函数的作用是获取当前归还期
	 * @author jzk
	 * @param con 数据库连接
	 * @return returnPeriod 当前归还期
	 * @throws SQLException
	 */
	public static int getReturnPeriod(Connection con) throws SQLException {
		int returnPeriod = 0;
		ResultSet rs;
		String queryScript = "select bookReturnPeriod from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			returnPeriod = rs.getInt(1);
		}
		rs.close();
		return returnPeriod;
	}

	/**
	 * 这个函数的作用是修改保证金
	 * @author jzk
	 * @param updaterUid       这是修改者的UID
	 * @param securityDeposit 这是修改后保证金的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateSecurityDeposit(int updaterUid, double securityDeposit) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		if (identity == 1) {
			if (securityDeposit < 0) {
				System.out.println("保证金必须为正数！");
				con.close();
				return -1;
			} else {
				String updateScript = "update SystemAttribute set readerSecurityDeposit =" + securityDeposit;
				int i = BasicOperation.executeUpdateScript(updateScript);
				con.close();
			}
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是修改保证金
	 * @author jzk
	 * @param con              数据库连接
	 * @param updaterUid       这是修改者的UID
	 * @param securityDeposit 这是修改后保证金的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateSecurityDeposit(Connection con, int updaterUid, double securityDeposit)
			throws SQLException {
		int identity = getIdentity(con, updaterUid);
		if (identity == 1) {
			if (securityDeposit < 0) {
				System.out.println("保证金必须为正数！");
				return -1;
			} else {
				String updateScript = "update SystemAttribute set readerSecurityDeposit =" + securityDeposit;
				return BasicOperation.executeUpdateScript(con, updateScript);
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是获取当前保证金
	 * @author jzk
	 * @return securityDeposit 当前保证金
	 * @throws SQLException
	 */
	public static double getSecurityDeposit() throws SQLException {
		double securityDeposit = 0;
		Connection con = BasicOperation.getConnection();
		ResultSet rs;
		String queryScript = "select readerSecurityDeposit from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			securityDeposit = rs.getDouble(1);
		}
		rs.close();
		con.close();
		return securityDeposit;
	}

	/**
	 * 这个函数的作用是获取当前保证金
	 * @author jzk
	 * @param con 数据库连接
	 * @return securityDeposit 当前保证金
	 * @throws SQLException
	 */
	public static double getSecurityDeposit(Connection con) throws SQLException {
		double securityDeposit = 0;
		ResultSet rs;
		String queryScript = "select readerSecurityDeposit from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			securityDeposit = rs.getDouble(1);
		}
		rs.close();
		return securityDeposit;
	}

	/**
	 * 这个函数的作用是修改预约保持期
	 * @author jzk
	 * @param updaterUid             这是修改者的UID
	 * @param reserveMaintainingHour 这是修改后预约保持期的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateReserveMaintainingHours(int updaterUid, int reserveMaintainingHours) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		if (identity == 1) {
			if (reserveMaintainingHours < 0) {
				System.out.println("预约保持期必须为正数！");
				con.close();
				return -1;
			} else {
				String updateScript = "update SystemAttribute set reserveMaintainingHours =" + reserveMaintainingHours;
				int i = BasicOperation.executeUpdateScript(con,updateScript);
				con.close();
				return i;
			}
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是修改预约保持期
	 * @author jzk
	 * @param con                    数据库连接
	 * @param updaterUid             这是修改者的UID
	 * @param reserveMaintainingHour 这是修改后预约保持期的值
	 * @return update 语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateReserveMaintainingHour(Connection con, int updaterUid, int reserveMaintainingHours)
			throws SQLException {
		int identity = getIdentity(con, updaterUid);
		if (identity == 1) {
			if (reserveMaintainingHours < 0) {
				System.out.println("预约保持期必须为正数！");
				return -1;
			} else {
				String updateScript = "update SystemAttribute set reserveMaintainingHours =" + reserveMaintainingHours;
				return BasicOperation.executeUpdateScript(con, updateScript);
			}
		}
		return -1;
	}

	/**
	 * 这个函数的作用是获取当前预约保持期
	 * @author jzk
	 * @return reserveMaintainingHour 当前预约保持期
	 * @throws SQLException
	 */
	public static int getReserveMaintainingHours() throws SQLException {
		int reserveMaintainingHours = 0;
		Connection con = BasicOperation.getConnection();
		ResultSet rs;
		String queryScript = "select reserveMaintainingHours from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			reserveMaintainingHours = rs.getInt(1);
		}
		rs.close();
		con.close();
		return reserveMaintainingHours;
	}

	/**
	 * 这个函数的作用是获取当前预约保持期
	 * @author jzk
	 * @param con 数据库连接
	 * @return reserveMaintainingHour 当前预约保持期
	 * @throws SQLException
	 */
	public static int getReserveMaintainingHours(Connection con) throws SQLException {
		int reserveMaintainingHours = 0;
		ResultSet rs;
		String queryScript = "select reserveMaintainingHours from SystemAttribute";
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			reserveMaintainingHours = rs.getInt(1);
		}
		rs.close();
		return reserveMaintainingHours;
	}

	/**
	 * 这个函数的作用是根据bid单独编辑图书信息(书名、作者、出版社、价格)，主要用于旧书
	 * @author jzk
	 * @param updaterUid   这是修改者的UID
	 * @param bookID       这是被修改的图书的bid
	 * @param newName      这是被修改的图书的新名字
	 * @param newAuthor    这是被修改图书的新作者
	 * @param newPublisher 这是被修改图书的新出版社
	 * @param newPrice     这是被修改图书的新价格
	 * @return update语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateBookInfoByBid(int updaterUid, int bookID, String newName, String newAuthor,
			String newPublisher, double newPrice) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		String originalName = null;
		String originalAuthor = null;
		String originalPublisher = null;
		double originalPrice = 0;
		ResultSet rs = BasicOperation.getQueryResult(con,
				"select name,author,publisher,price from Book where bid =" + bookID);
		if (rs.next()) {
			originalName = rs.getString(1);
			originalAuthor = rs.getString(2);
			originalPublisher = rs.getString(3);
			originalPrice = rs.getDouble(4);
		}
		if (newName == null) {
			newName = originalName;
		}
		if (newAuthor == null) {
			newAuthor = originalAuthor;
		}
		if (newPublisher == null) {
			newPublisher = originalPublisher;
		}
		if (newPrice <= 0.0) {
			newPrice = originalPrice;
		}
		if (identity == 2) {
			newName = "'" + newName + "'";
			newAuthor = "'" + newAuthor + "'";
			newPublisher = "'" + newPublisher + "'";
			String updateScript = "update Book set name =" + newName + ", author =" + newAuthor + ", publisher ="
					+ newPublisher + ", price =" + newPrice + "where ISBN =" + bookID;
			int i = BasicOperation.executeUpdateScript(con,updateScript);
			con.close();
			return i;
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是根据bid单独编辑图书信息(书名、作者、出版社、价格)，主要用于旧书
	 * @author jzk
	 * @param con          数据库连接
	 * @param updaterUid   这是修改者的UID
	 * @param bookID       这是被修改的图书的bid
	 * @param newName      这是被修改的图书的新名字
	 * @param newAuthor    这是被修改图书的新作者
	 * @param newPublisher 这是被修改图书的新出版社
	 * @param newPrice     这是被修改图书的新价格
	 * @return update语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateBookInfoByBid(Connection con, int updaterUid, int bookID, String newName, String newAuthor,
			String newPublisher, double newPrice) throws SQLException {
		int identity = getIdentity(con, updaterUid);
		String originalName = null;
		String originalAuthor = null;
		String originalPublisher = null;
		double originalPrice = 0;
		ResultSet rs = BasicOperation.getQueryResult(con,
				"select name,author,publisher,price from Book where ISBN =" + bookID);
		if (rs.next()) {
			originalName = rs.getString(1);
			originalAuthor = rs.getString(2);
			originalPublisher = rs.getString(3);
			originalPrice = rs.getDouble(4);
		}
		if (newName == null||newName.equals("")) {
			newName = originalName;
		}
		if (newAuthor == null||newAuthor.equals("")) {
			newAuthor = originalAuthor;
		}
		if (newPublisher == null||newPublisher.equals("")) {
			newPublisher = originalPublisher;
		}
		if (newPrice <= 0.0) {
			newPrice = originalPrice;
		}
		if (identity == 2) {
			newName = "'" + newName + "'";
			newAuthor = "'" + newAuthor + "'";
			newPublisher = "'" + newPublisher + "'";
			String updateScript = "update Book set name =" + newName + ", author =" + newAuthor + ", publisher ="
					+ newPublisher + ", price =" + newPrice + " where ISBN =" + bookID;
			return BasicOperation.executeUpdateScript(con, updateScript);
		}
		return -1;
	}

	/**
	 * 这个函数的作用是编辑相同ISBN的图书信息(书名、作者、出版社、价格)，用于新书
	 * @author jzk
	 * @param updaterUid   这是修改者的UID
	 * @param bookISBN     这是被修改的图书的ISBN
	 * @param newName      这是被修改的图书的新名字
	 * @param newAuthor    这是被修改图书的新作者
	 * @param newPublisher 这是被修改图书的新出版社
	 * @param newPrice     这是被修改图书的新价格
	 * @return update语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateBookInfoByISBN(int updaterUid, String ISBN, String newName, String newAuthor,
			String newPublisher, double newPrice) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con,updaterUid);
		ISBN = "'" + ISBN + "'";
		String originalName = null;
		String originalAuthor = null;
		String originalPublisher = null;
		double originalPrice = 0;
		ResultSet rs = BasicOperation.getQueryResult(con,
				"select name,author,publisher,price from Book where bid =" + ISBN);
		if (rs.next()) {
			originalName = rs.getString(1);
			originalAuthor = rs.getString(2);
			originalPublisher = rs.getString(3);
			originalPrice = rs.getDouble(4);
		}
		if (newName == null||newName.equals("")) {
			newName = originalName;
		}
		if (newAuthor == null||newAuthor.equals("")) {
			newAuthor = originalAuthor;
		}
		if (newPublisher == null||newPublisher.equals("")) {
			newPublisher = originalPublisher;
		}
		if (newPrice <= 0.0) {
			newPrice = originalPrice;
		}
		if (identity == 2) {
			newName = "'" + newName + "'";
			newAuthor = "'" + newAuthor + "'";
			newPublisher = "'" + newPublisher + "'";
			String updateScript = "update Book set name =" + newName + ", author =" + newAuthor + ", publisher ="
					+ newPublisher + ", price =" + newPrice + "where ISBN =" + ISBN;
			int i = BasicOperation.executeUpdateScript(con,updateScript);
			return i;
		}
		con.close();
		return -1;
	}

	/**
	 * 这个函数的作用是编辑ISBN相同的图书信息(书名、作者、出版社、价格)，主要用于新书
	 * @author jzk
	 * @param con          数据库连接
	 * @param updaterUid   这是修改者的UID
	 * @param bookID       这是被修改的图书的bid
	 * @param newName      这是被修改的图书的新名字
	 * @param newAuthor    这是被修改图书的新作者
	 * @param newPublisher 这是被修改图书的新出版社
	 * @param newPrice     这是被修改图书的新价格
	 * @return update语句自带的返回值
	 * @throws SQLException
	 */
	public static int updateBookInfoByISBN(Connection con, int updaterUid, String ISBN, String newName,
			String newAuthor, String newPublisher, double newPrice) throws SQLException {
		int identity = getIdentity(con, updaterUid);
		ISBN = "'" + ISBN + "'";
		String originalName = null;
		String originalAuthor = null;
		String originalPublisher = null;
		double originalPrice = 0;
		ResultSet rs = BasicOperation.getQueryResult(con,
				"select name,author,publisher,price from Book where ISBN =" + ISBN);
		if (rs.next()) {
			originalName = rs.getString(1);
			originalAuthor = rs.getString(2);
			originalPublisher = rs.getString(3);
			originalPrice = rs.getDouble(4);
		}
		if (newName == null||newName.equals("")) {
			newName = originalName;
		}
		if (newAuthor == null||newAuthor.equals("")) {
			newAuthor = originalAuthor;
		}
		if (newPublisher == null||newPublisher.equals("")) {
			newPublisher = originalPublisher;
		}
		if (newPrice <= 0.0) {
			newPrice = originalPrice;
		}
		if (newPrice <= 0.0) {
			newPrice = originalPrice;
		}
		if (identity == 2) {
			newName = "'" + newName + "'";
			newAuthor = "'" + newAuthor + "'";
			newPublisher = "'" + newPublisher + "'";
			String updateScript = "update Book set name =" + newName + ", author =" + newAuthor + ", publisher ="
					+ newPublisher + ", price =" + newPrice + " where ISBN =" + ISBN;
			return BasicOperation.executeUpdateScript(con, updateScript);
		}
		return -1;
	}

	/**
	 * 这个函数的作用是删除图书库里指定bookid的图书
	 * @author hlk
	 * @param librarianUid 删除图书的图书管理员的uid
	 * @param bookID       被删除图书的bookid
	 * @param reason       删除原因
	 * @return sql语句默认值
	 * @throws SQLException
	 */
	public static int getBookDeleted(int librarianUid, String bookID, String reason) throws SQLException {
		Connection con = BasicOperation.getConnection();
		int identity = getIdentity(con, librarianUid);
		if (identity != 2) return -1;
		int bid = 0;
		bookID = "'" + bookID + "'";
		reason = "'" + reason + "'";
		ResultSet rs;
		String queryScript = "select bid from SpecificBook where bookID = " + bookID;
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			bid = rs.getInt(1);
		}
		rs.close();
		if (bid == 0) {
			con.close();
			return -1;
		}
		queryScript = "delete from SpecificBook where bookID = " + bookID;
		BasicOperation.executeUpdateScript(con, queryScript);
		queryScript = "insert into DeleteList (uid, bid, bookID, date ,reason) values(" + librarianUid + "," + bid + ","
				+ bookID + ",'" + dataOperator.BasicOperation.getDateWithTimeInString() + "'," + reason + ")";
		int i = BasicOperation.executeUpdateScript(con,queryScript);
		con.close();
		return i;
	}

	/**
	 * 这个函数的作用是删除图书库里指定bookid的图书
	 * @author hlk
	 * @param con          数据库连接
	 * @param librarianUid 删除图书的图书管理员的uid
	 * @param bookID       被删除图书的bookid
	 * @param reason       删除原因
	 * @return sql语句默认值
	 * @throws SQLException
	 */
	public static int getBookDeleted(Connection con, int librarianUid, String bookID, String reason)
			throws SQLException {
		int identity = getIdentity(con, librarianUid);
		if (identity != 2) return -1;
		int bid = 0;
		bookID = "'" + bookID + "'";
		reason = "'" + reason + "'";
		ResultSet rs;
		String queryScript = "select bid from SpecificBook where bookID =" + bookID;
		rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next()) {
			bid = rs.getInt(1);
		}
		rs.close();
		if (bid == 0) {
			return -1;
		}
		queryScript = "delete from SpecificBook where bookID =" + bookID;
		BasicOperation.executeUpdateScript(con, queryScript);
		queryScript = "insert into DeleteList (uid, bid, bookID, date ,reason) values(" + librarianUid + "," + bid + ","
				+ bookID + ",'" +dataOperator.BasicOperation.getDateWithTimeInString() + "'," + reason + ")";
		return BasicOperation.executeUpdateScript(con, queryScript);
	}
	/**
	 * 这个函数的作用是删除reader用户的信息
	 * @author hlk
	 * @param con          数据库连接
	 * @param librarianUid 删除reader的图书管理员的uid
	 * @param ReaderUid 被删除用户的uid
	 * @return sql语句默认值
	 * @throws SQLException
	 */
	public static int getReaderDeleted(Connection con, int librarianUid, int ReaderUid)
			throws SQLException {
		int identity = getIdentity(con, librarianUid);
		if (identity != 2)
			return -1;
		String sql = "select count(*) from BorrowList where uid='" + ReaderUid + "' and status='borrowed'";
		ResultSet res = BasicOperation.getQueryResult(con, sql);
		if (!res.next()||res.getInt(1)>0)return -2;
		sql = "delete from User where uid =" + ReaderUid;
		BasicOperation.executeUpdateScript(con, sql);
		return 1;
	}
	/**
	 * 这个函数的作用是根据uid获取email地址
	 * @param uid 用户uid
	 * @return 用户email地址
	 * @throws SQLException
	 */
	public static String getEmailByUid(int uid) throws SQLException {
	Connection con = BasicOperation.getConnection();
	String queryScript = "select Email from User where uid =" + uid;
	String email = null;
	ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
	if(rs.next()) {
		email = rs.getString(1);
	}
	rs.close();
	con.close();
	return email;
	}
	/**
	 * 这个函数的作用是根据uid获取email地址
	 * @param con 数据库连接
	 * @param uid 用户uid
	 * @return 用户email地址
	 * @throws SQLException
	 */
	public static String getEmailByUid(Connection con, int uid) throws SQLException {
	String queryScript = "select Email from User where uid =" + uid;
	String email = null;
	ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
	if(rs.next()) {
		email = rs.getString(1);
	}
	rs.close();
	return email;
	}
	/**
	 * 这个函数的作用是根据uid获取用户电话号码
	 * @param uid 用户uid
	 * @return 用户电话号码
	 * @throws SQLException
	 */
	public static String getPhoneNumberByUid(int uid) throws SQLException {
	Connection con = BasicOperation.getConnection();
	String queryScript = "select phoneNumber from User where uid =" + uid;
	String phoneNumber = null;
	ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
	if(rs.next()) {
		phoneNumber = rs.getString(1);
	}
	rs.close();
	con.close();
	return phoneNumber;
	}
	/**
	 * 这个函数的作用是根据uid获取用户电话号码
	 * @param con 数据库连接
	 * @param uid 用户uid
	 * @return 用户电话号码
	 * @throws SQLException
	 */
	public static String getPhoneNumberByUid(Connection con, int uid) throws SQLException {
	String queryScript = "select phoneNumber from User where uid =" + uid;
	String phoneNumber = null;
	ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
	if(rs.next()) {
		phoneNumber = rs.getString(1);
	}
	rs.close();
	return phoneNumber;
	}
	//

	/**
	 * 这个函数的作用是列出该读者所借的书目
	 * 
	 * @param con 数据库链接
	 * @param uid 读者的uid
	 * @return 返回读者借书的书目
	 * @throws SQLException
	 */
	public static ResultSet getReaderBorrowList(Connection con, int uid) throws SQLException {
		String selectScript = "select * from BorrowList where uid=" + uid;
		ResultSet rs = BasicOperation.getQueryResult(con, selectScript);
		ResultSetMetaData rsmd = rs.getMetaData();
		int columns = rsmd.getColumnCount();
		while (rs.next()) {
			for (int i = 1; i <= columns; i++) {
				System.out.print(rs.getString(i) + "\t");
			}
			System.out.println();
		}
		// 将rs的指针重新移回到第一行的位置
		rs.beforeFirst();
		return rs;
	}

	/**
	 * 
	 * 这个函数的作用是更新借书列表，如果指定的书本已经在列表中且存在借出状态，则将其更新为已归还，或禁止再次借出
	 * 
	 * @author Admin
	 * @param bookID    书本的bookID
	 * @param readerUid 读者的uid
	 * @param status    借书列表中书本的状态，取值只能为borrowed(已借出)
	 *                  returned(已归还)，当书本已归还时状态内要追加归还日期，同时更新SpecificBook中的书本状态
	 * @throws SQLException
	 * 
	 */
	public static int updateBorrowList(Connection con, String bookID, int librarianUid, int readerUid, String status)
			throws SQLException {
		if ((getIdentity(con, librarianUid) != 2) || getIdentity(con, readerUid) != 3)
			return -1;
		if (!(status.equals("returned") || status.equals("borrowed")))
			return -1;
		if (status.equals("borrowed")) {
			String queryScript = "select * from BorrowList where bookID = '" + bookID + "' and status = 'borrowed'";
			ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
			// 不能将已经借出的书再次借出
			if (rs.next())
				return -1;
			queryScript = "select bid from SpecificBook where bookID='" + bookID + "'";
			rs = BasicOperation.getQueryResult(con, queryScript);
			int bid = 0;
			if (!rs.next())
				return -1;
			bid = rs.getInt(1);
			String updateScript = "insert into BorrowList values ('" + readerUid + "','"+bid+"','" + bookID + "','"
					+ dataOperator.BasicOperation.getDateWithTimeInString() + "','borrowed')";
			return BasicOperation.executeUpdateScript(con, updateScript);
		}
		if (status.equals("returned")) {
			String updateScript = "update BorrowList set status = 'returned (Date = "
					+ dataOperator.BasicOperation.getDateWithTimeInString() + ")' where bookID = '" + bookID
					+ "' and uid = " + readerUid;
			updateBookStatus(con, bookID, librarianUid, readerUid, "available");
			return BasicOperation.executeUpdateScript(con, updateScript);
		}
		return -1;
	}

	/**
	 * 这个函数的作用是更新该书目状态，如果是更新为借出状态函数会进一步更新borrowList
	 * @author Admin
	 * @param con          数据库链接
	 * @param bookID       书目的bookID
	 * @param librarianUid 图书管理员的uid，不要填为定值
	 * @param readerUid    读者的uid，不要填为定值
	 * @param status       书本当前状态，取值应该为 available(在馆) borrowed(已借出)
	 * @throws SQLException
	 */
	public static int updateBookStatus(Connection con, String bookID, int librarianUid, int readerUid, String status)
			throws SQLException {
		// 身份验证
		if ((getIdentity(con, librarianUid) != 2) || getIdentity(con, readerUid) != 3)
			return -1;
		// 字符串取值检查
		if (!(status.equals("available") || status.equals("borrowed")))
			return -1;
		String updateScript = "update SpecificBook set status = '" + status + "' where bookID ='" + bookID + "'";
		BasicOperation.executeUpdateScript(con, updateScript);
		if (status.equals("borrowed")) {
			return updateBorrowList(con, bookID, librarianUid, readerUid, status);
		}
		return -1;
	}

	/**
	 * 这个函数的作用是提供bid和uid以便预约书
	 * @author hlk
	 * 流程： 1.查询这本书是否已经被这个读者预约了，如果是，则禁止重复预约，并返回
	 * 2.将这本书加入预约列表，过期时间根据当前时间和数据库取得的参数设定，状态置为"reserving" 3.此操作对SpecificBook无任何影响
	 * 
	 * @param con       数据库链接
	 * @param bid       书本的ID号
	 * @param readerUid 读者的uid
	 * @return 返回预约的bookID提供给预约功能，如果已经预约过一本或者没有可供预约的书，则返回空字符串(预约不应该针对具体的一本书，还要继续改)
	 * @throws SQLException
	 * @throws ParseException
	 */
	public static int getBookReserved(Connection con, int bid, int readerUid) throws SQLException, ParseException {
		// 身份验证
		if (getIdentity(con, readerUid) != 3)
			return -1;
		// 同一本书不能多次预约
		getExpiredReserveInvalidate(con, bid);
		String queryScript = "select * from ReserveList where uid = " + readerUid + " and bid = " + bid
				+ " and status = 'reserving'";
		ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
		if (rs.next())
			return -1;
		int reserveMaintainingHours = getReserveMaintainingHours(con);
		String updateScript = "insert into ReserveList values(" + readerUid + "," + bid + ",'"
				+ dataOperator.BasicOperation.getDateWithTimeAfterHours(reserveMaintainingHours) + "','reserving')";
		return BasicOperation.executeUpdateScript(con, updateScript);
	}

	/**
	 * 将所有当前时间超过expireDate的ReserveList项的状态置为"expired"
	 * @author hlk
	 * @return
	 * @throws SQLException
	 * @throws ParseException
	 */
	private static int getExpiredReserveInvalidate(Connection con, int bid) throws SQLException, ParseException {
		String getList = "select expirationDate from ReserveList where bid='" + bid + "'and status='reserving'";
		ResultSet List = BasicOperation.getQueryResult(con, getList);
		long recentTime = System.currentTimeMillis();
		int n = 0;
		String sql = null;
		Date date = null;
		String formatdate = null;
		while (List.next()) {
			formatdate = List.getString("expirationDate");
			date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(formatdate);
			if (date.getTime() < recentTime) {
				sql = "update ReserveList set status = 'expired' where bid = '" + bid + "' and expirationDate = '"
						+ formatdate + "'";
				BasicOperation.executeUpdateScript(con, sql);
				n++;
			}
		}
		return n;
	}

	/**
	 * 这个函数的作用是将读者预约的书借出，必须由图书管理员调用 流程： 1.判定两人的身份是否正确，如果不正确直接返回
	 * 2.调用getExpiredReserveInvalidate()，将过期的预约记录全部置为"expired"
	 * 3.查询是否有【正在预约"reserving"】的预约记录，如果有，管理员找出一本状态为"available"的书借给读者，调用updateBookStatus(...)将状态置为"borrowed"，同时将本预约记录的状态改为"borrowed"
	 * 
	 * @param con
	 * @param bookID
	 * @param librarianUid
	 * @param readerUid
	 * @return
	 * @throws SQLException
	 * @throws ParseException
	 */
	public static boolean getBookBorrowed(Connection con, String bookID, int librarianUid, int readerUid)
			throws SQLException, ParseException {
		int identity = getIdentity(con, librarianUid);
		if (identity != 2)
			return false;
        String sql = "select count(*) from BorrowList where uid='" + readerUid + "' and status='borrowed'";
		ResultSet res = BasicOperation.getQueryResult(con, sql);
		if (!res.next()||res.getInt(1)>=3)return false;
		sql = "select bid from SpecificBook where bookID='" + bookID + "'";
		res = BasicOperation.getQueryResult(con, sql);
		int bid = 0;
		if (!res.next())
			return false;
		bid = res.getInt(1);
		getExpiredReserveInvalidate(con, bid);
		sql = "select * from ReserveList where uid='" + readerUid + "'and bid='" + bid + "' and status='reserving'";
		res = BasicOperation.getQueryResult(con, sql);
		if (!res.next()) {
			if (!getBookBorrowedDirectly(con, bookID, librarianUid, readerUid))
				return false;
		} else {
			sql = "update ReserveList set status='borrowed' where uid='" + readerUid + "'and bid='" + bid
					+ "' and status ='reserving'";
			BasicOperation.executeUpdateScript(con, sql);
			if (updateBookStatus(con, bookID, librarianUid, readerUid, "borrowed") == -1)
				return false;
		}
		return true;
	}

	/**
	 * 这个函数的作用是根据借书日期，判断应付地罚金，若没过期，返回-1
	 * 
	 * @param con     数据库连接
	 * @param datestr 借书日期
	 * @return 罚金额
	 * @throws SQLException
	 * @throws ParseException
	 * 
	 */
	public static double getExpiredFine(Connection con, String datestr) throws ParseException, SQLException {
		Date date = new SimpleDateFormat("yyyy-MM-dd").parse(datestr);
		int days = getReturnPeriod(con);
		double fine = getFineValue(con);
		double deposit = getSecurityDeposit(con);
		Calendar cld = Calendar.getInstance();
		cld.setTime(date);
		cld.add(Calendar.DAY_OF_MONTH, days);
		date = cld.getTime();
		long et = (new Date()).getTime() - date.getTime();
		et = et / (1000 * 3600 * 24);
		fine = fine * et;
		if (et > 0)
			return fine > deposit ? deposit : fine;
		return -1.0;
	}

	/**
	 * 这个函数的作用是图书管理员还书 还书流程:1判断身份 2查询借书日期判断是否过期，如果过期则在FineList中添加罚金记录reason为Fine
	 * 3删除FineList中该借书信息的保证金记录
	 * 
	 * @param con          数据库连接
	 * @param bookID       借的书的bookID
	 * @param librarianUid 操作者UID
	 * @param readerUid    读者UID
	 * @return 操作是否成功
	 * @throws SQLException
	 * @throws ParseException
	 * 
	 */
	public static boolean getBookReturned(Connection con, String bookID, int librarianUid, int readerUid, double fine)
			throws SQLException, ParseException {
		int identity = getIdentity(con, librarianUid);
		if (identity != 2)
			return false;
		else {
			updateBorrowList(con, bookID, librarianUid, readerUid, "returned");
			if(fine>0){
			String sql = "insert into FineList values(" + readerUid + ",'" + bookID + "','"
					+ dataOperator.BasicOperation.getDateWithTimeInString() + "'," + fine + ",'Fine')";
			BasicOperation.executeUpdateScript(con, sql);
			}
		}
		return true;
	}

	/**
	 * 这个函数的作用是直接将书借出，必须由图书管理员调用 流程： 1.判定两人的身份是否正确，如果不正确直接返回
	 * 2.调用getExpiredReserveInvalidate()，将过期的预约记录全部置为"expired"
	 * 3.查询排除被预约的状态为"available"书，如果有，管理员找出一本借给读者，调用updateBookStatus(...)将状态置为"borrowed"
	 * 
	 * @param con
	 * @param bookID
	 * @param librarianUid
	 * @param readerUid
	 * @return
	 * @throws SQLException
	 * @throws ParseException
	 */
	private static boolean getBookBorrowedDirectly(Connection con, String bookID, int librarianUid, int readerUid)
			throws SQLException, ParseException {
		int identity = getIdentity(con, librarianUid);
		if (identity != 2)
			return false;
		String sql = "select bid from SpecificBook where bookID='" + bookID + "'";
		ResultSet res = BasicOperation.getQueryResult(con, sql);
		int bid = 0;
		if (!res.next())
			return false;
		bid = res.getInt(1);
		getExpiredReserveInvalidate(con, bid);
		sql = "select count(*) from ReserveList where bid='" + bid + "'and status ='reserving'";
		res = BasicOperation.getQueryResult(con, sql);
		res.next();
		int n = res.getInt(1);
		sql = "select count(*) from SpecificBook where status='available' and bid='" + bid + "'";
		res = BasicOperation.getQueryResult(con, sql);
		res.next();
		int m = res.getInt(1);
		if (m <= n)
			return false;
		if (updateBookStatus(con, bookID, librarianUid, readerUid, "borrowed") == -1)
			return false;
		return true;
	}
    /**
	 * 这个函数的作用是获取图书馆收入结果集
	 * @param con 数据库连接
	 * @param incometype 收入类型 Deposit/Fine
	 * @param timerange 时间区域 按日/按周/按月
	 * @return 按日/周/月整合排序好的结果集，第一列为每日/周/月，第二列为收入
	 * @throws SQLException
     * @author jiazekun
	 */
	public static ResultSet getIncome(Connection con, String incometype, String timerange) throws SQLException {
		ResultSet rs = null;
		String sql = null;
		if(incometype.equals("Total")) {
			switch(timerange) {
			case "Daily":
				sql = "SELECT DATE_FORMAT(date,'%Y-%m-%d') as date, SUM(amount) as amount FROM FineList GROUP BY DATE_FORMAT(date,'%Y-%m-%d')";
				break;
			case "Weekly":
				sql = "SELECT DATE_FORMAT(date,'%Y-%u') as date, SUM(amount) as amount FROM FineList GROUP BY DATE_FORMAT(date,'%Y-%u')";
				break;
			case "Monthly":
				sql = "SELECT DATE_FORMAT(date,'%Y-%m') as date, SUM(amount) as amount FROM FineList GROUP BY DATE_FORMAT(date,'%Y-%m')";
				break;
			}
		}
		else {
			switch(timerange) {
			case "Daily":
				sql = "SELECT DATE_FORMAT(date,'%Y-%m-%d') as date, SUM(amount) as amount FROM FineList where reason='" + incometype + "' GROUP BY DATE_FORMAT(date,'%Y-%m-%d')";
				break;
			case "Weekly":
				sql = "SELECT DATE_FORMAT(date,'%Y-%u') as date, SUM(amount) as amount FROM FineList where reason='" + incometype + "' GROUP BY DATE_FORMAT(date,'%Y-%u')";
				break;
			case "Monthly":
				sql = "SELECT DATE_FORMAT(date,'%Y-%m') as date, SUM(amount) as amount FROM FineList where reason='" + incometype + "' GROUP BY DATE_FORMAT(date,'%Y-%m')";
				break;
			}
		}
		rs = BasicOperation.getQueryResult(con, sql);
		return rs;
	}
	/*
	 * 使用这个主函数可以测试数据库的连接是否正常。 public static void main(String[] args) throws
	 * SQLException { System.out.println(getIdentity(1)); Date date=new Date();
	 * SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); }
	 */
	
	/**
	 * 这个函数用于查询现有图书管理员的信息，必须由超级管理员调用
	 * @author hunter
	 * @param con
	 * @param inputValue
	 * @param condition
	 * @return
	 * @throws SQLException
	 */
	public static ResultSet getLibrarianInfo(Connection con, String inputValue, String condition) throws SQLException {
		if (condition.equals("uid")) { // 根据读者ID进行查询
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where uid = '" + inputValue
							+ "' and identity = 2");
			return rs;
		}
		if (condition.equals("Email")) { // 根据Email进行查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where Email like '%" + inputValue + "%' and identity = 2");
			return rs;
		}
		else{ //根据phoneNumber进行查询
			inputValue.replaceAll(" ", "%");
			ResultSet rs = BasicOperation.getQueryResult(con,
					"select * from User where phoneNumber like '%" + inputValue + "%' and identity = 2");
			return rs;
		}
	}
	/**
	 * 获取公告栏中的信息
	 * @return 公告栏信息
	 * @throws SQLException 
	 */
	public static String getAnnouncement(Connection con) throws SQLException {
		String queryScript = "select announcement from SystemAttribute";
		ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
		if(rs.next()&&(rs.getString(1)!=null)) return rs.getString(1);
		return "No Announcements Yet";
	}
	/**
	 * 获取公告栏中的信息
	 * @author Admin
	 * @return 公告栏信息
	 * @throws SQLException 
	 */
	public static String getAnnouncement() throws SQLException {
		String queryScript = "select announcement from SystemAttribute";
		Connection con = BasicOperation.getConnection();
		ResultSet rs = BasicOperation.getQueryResult(con, queryScript);
		String announcement = null;
		if(rs.next()) {
			announcement = rs.getString(1);
		}
		con.close();
		if(announcement!=null) return announcement;
		return "No Announcements Yet";
	}
	
	/**
	 * 本函数用于更新公告，只能由图书管理员调用
	 * (未经验证，可能存在错误)
	 * @author Admin
	 * @param con 数据库连接
	 * @param uid 图书管理员uid
	 * @param title 公告标题
	 * @param announcement 新公告内容
	 * @return
	 * @throws SQLException
	 */
	public static int setAnnouncement(Connection con,int uid,String title, String announcement) throws SQLException{
		if(getIdentity(con,uid)!=2) return -1;
		String res = "<h4>" + title + "</h4>" + announcement + "<br>Updated at:" + dataOperator.BasicOperation.getDateWithTimeInString() + "<br>";
		String updateScript = "update SystemAttribute set announcement = '" + res + "'";
		return BasicOperation.executeUpdateScript(con,updateScript);
	}
    
	/**
	 * 本函数用于查看书本删除记录
	 * @author Admin
	 * @param con 数据库连接
	 * @return
	 * @throws SQLException
	 */
	public static ResultSet getDeleteList(Connection con)throws SQLException {
		String sql = "select * from DeleteList order by date desc";
		ResultSet res = BasicOperation.getQueryResult(con, sql);
		return res;
	}
	
	/**
	 * 本函数用于删除读者时退回保证金
	 * @param con 数据库连接
	 * @param readerid 读者uid
	 * @throws SQLException
	 */
	public static void getDepositDeleted(Connection con, int readerid) throws SQLException {
		String sql = "delete from FineList where uid=" + readerid + " and reason='Deposit'";
		BasicOperation.executeUpdateScript(con,sql);
	}
	
}
